package com.cuz.hot100;

public class Q88Merge2Array {


    public void merge(int[] nums1, int m, int[] nums2, int n) {
        int index1 = m - 1;
        int index2 = n - 1;
        int lastIndexZero = m + n - 1;
        while (index1 >= 0 || index2 >= 0) {
            int curValue;
            if (index1 == -1) {
                curValue = nums2[index2];
                index2--;
            } else if (index2 == -1) {
                curValue = nums1[index1];
                index1--;
            } else if (nums1[index1] > nums2[index2]) {
                curValue = nums1[index1];
                index1--;
            } else {
                curValue = nums2[index2];
                index2--;
            }
            nums1[lastIndexZero--] = curValue;
        }
    }
}
